/*
 +----------------------------------------------------------------------
 + Title        : 分类 pinia 存储
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2023-07-08
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 分类 pinia 存储
 +----------------------------------------------------------------------
*/

import { reqGetCategoryTreesAPI } from '@/apis/category'
import { defineStore } from "pinia"
import { ref } from "vue"

export const useCategoryStore = defineStore('category', () => {
    
    // 定义分类信息
    const categoryList = ref([])

    /**
     * 获取分类树
     * @param data 
     */
    const getCategoryTrees = async (data) => {
        if (categoryList.value.length == 0) {
            const result = await reqGetCategoryTreesAPI(data)
            result.data.categories.forEach((item,index) => {
                switch (index) {
                    case 11:
                        item.iconfont = 'icon-079aiqing'
                        break;
                    case 12:
                        item.iconfont = 'icon-meigui'
                        break;
                    case 13:
                        item.iconfont = 'icon-shengri'
                        break;
                    case 14:
                        item.iconfont = 'icon-youqing'
                        break;
                    case 15:
                        item.iconfont = 'icon-jieriwenhou'
                        break;
                    case 16:
                        item.iconfont = 'icon-weiwen'
                        break;
                    case 17:
                        item.iconfont = 'icon-songligandong-'
                        break;
                    case 18:
                        item.iconfont = 'icon-zhuhe'
                        break;
                    case 19:
                        item.iconfont = 'icon-hunqing'
                        break;
                    case 20:
                        item.iconfont = 'icon-shangwu'
                        break;
                    case 21:
                        item.iconfont = 'icon-quweixing'
                        break;
                    case 22:
                        item.iconfont = 'icon-tubiaozhizuomoban-'
                        break;
                    default:
                        break;
                }
            });
            categoryList.value = result.data.categories
        }
    }


    return {
        categoryList,
        getCategoryTrees
    }
},

// 持久化
{
    persist: true,
})